package com.byq.ai.agentlab.controller;

import com.byq.ai.agentlab.po.MyConversation;
import com.byq.ai.agentlab.service.CharacterService;
import com.byq.ai.agentlab.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("chat")
public class ChatController {
    @Autowired
    ChatService service;
    @Autowired
    CharacterService cservice;
    @RequestMapping("ask")
    @PreAuthorize("hasAuthority('chat')")
    public Result chat(String q, String cid) {
        String answer =  service.ask(q,cid);
        Result rst = new Result(answer);
        return  rst;
    }
    @RequestMapping("characters")
    public List<String> characters() {

        return  cservice.getCharaters();
    }

    @GetMapping("history")
    public List<SimpleConversation> hostory(){
        List<SimpleConversation> rst = new ArrayList<>();
        rst.add(new SimpleConversation("123", "xxx", new Date()));
        return rst;
    }
    @GetMapping("conversation")
    MyConversation getConverstaion(String id){
        return null;
    }
}
class SimpleConversation{
    public String id;

    public SimpleConversation(String id, String title, Date timestamp) {
        this.id = id;
        this.title = title;
        this.timestamp = timestamp;
    }

    public String title;
    public Date timestamp;
}
class Result{
    String answer;

    public String getAnswer() {
        return answer;
    }

    public Result(String answer) {
        this.answer = answer;
    }
}